<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:p="http://primefaces.prime.com.tr/ui">

<ui:composition>

	<article>
		
		<header><h2>Staff Management</h2></header>
			
		<div class="content">
			
			<h:form id="registration-form">
				
				<p:growl id="notice" showDetail="true" />
				
				<fieldset>
					
					<div class="grid_7 alpha">
						
						<label>
							E-mail: 
							<h:inputText value="#{mStaff.staff.email}" id="acc_email"
									validator="#{mValidatorLib.EmailValidate}" />
						</label> 
						
						<label>
							Password:
							<h:inputSecret value="#{mStaff.staff.password}" id="acc_pwd"
									validator="#{mValidatorLib.PasswordValidate}" />
						</label>
						
					</div>

					<div class="grid_8 omega">
						
						<label>
							Full Name: 
							<h:inputText value="#{mStaff.staff.fullname}" id="acc_name"
									validator="#{mValidatorLib.FullnameValidator}" />
						</label>
						
						<label>
							Account Status: 
							<h:selectOneMenu value="#{mStaff.staff.status}">
								<f:selectItem itemValue="False" itemLabel="Deactivate" />
								<f:selectItem itemValue="True" itemLabel="Activate" />
							</h:selectOneMenu> 
						</label>
						
						<div class="wrapper">
							<a4j:commandLink value="Insert" styleClass="button" execute="registration-form"
								action="#{mStaff.AddNewStaff}" render="staff_table, notice" />
						</div>
						
					</div>
				</fieldset>
			</h:form>
		</div>
	</article>
	
	<article>
		
		<header class="alt"><h2>All Staff</h2></header>
		
		<h:form prependId="false">
	
			<p:growl id="messages" showDetail="true" />
	
			<p:dataTable var="items" value="#{mStaff.allStaff}" paginator="true"
				paginatorAlwaysVisible="false" id="staff_table" rows="10"
				dynamic="true" onRowEditUpdate="messages"
				rowEditListener="#{mStaff.updateRow}">
	
				<p:column>
					<f:facet name="header"></f:facet>
					<p:rowToggler />
				</p:column>
	
				<p:column sortBy="#{items.email}" filterBy="#{items.email}"
						filterMatchMode="contains">
					<f:facet name="header">
						<h:outputText value="Email" />
					</f:facet>
					<h:outputText value="#{items.email}" />
				</p:column>
	
				<p:column sortBy="#{items.fullname}" filterBy="#{items.fullname}"
						filterMatchMode="contains">
					<f:facet name="header">
						<h:outputText value="Name" />
					</f:facet>
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{items.fullname}" />
						</f:facet>
						<f:facet name="input">
							<h:inputText value="#{items.fullname}" id="acc_name"
									validator="#{mValidatorLib.FullnameValidator}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
	
				<p:column sortBy="#{items.join_date}">
					<f:facet name="header">
						<h:outputText value="Join Date" />
					</f:facet>
					<h:outputText value="#{items.join_date}" />
				</p:column>
	
	
				<p:column sortBy="#{items.status}">
					<f:facet name="header">Status</f:facet>
					<p:cellEditor>
						<f:facet name="output">
							<h:outputText value="#{mStaff.validStatus(items.status)}" />
						</f:facet>
						<f:facet name="input">
							<h:selectBooleanCheckbox value="#{items.status}" />
						</f:facet>
					</p:cellEditor>
				</p:column>
	
				<p:column headerText="Edit">
					<p:rowEditor />
				</p:column>
				
				<p:rowExpansion>
					<div class="box3">
						<div class="prop_info">
							<ul class="list1">
								<li><strong>Join Date: </strong> <h:outputText
										value="#{items.join_date}" /></li>
								<li><strong>Name: </strong> <h:outputText
										value="#{items.fullname}" /></li>
								<li><strong>Email: </strong> <h:outputText
										value="#{items.email}" /></li>
								<li><strong>Status: </strong> <h:outputText
										value="#{mStaff.validStatus(items.status)}" /></li>
								<li>
									<a4j:commandLink render="pwdGrid"
											execute="@this" oncomplete="pwdDialog.show()"> 
										<b style="color:white">Reset Password</b>
										<f:setPropertyActionListener target="#{mStaff.staff}"
												value="#{items}" />
									</a4j:commandLink> 
								</li>
							</ul>
						</div>
					</div>
				</p:rowExpansion>
	
			</p:dataTable>
			
			<p:dialog header="Reset Password" widgetVar="pwdDialog" resizable="false"
				minWidth="400" showEffect="puff" hideEffect="puff" id="pwdDialog">
				
					<h:panelGrid id="pwdGrid" columns="2" cellpadding="4">
						
						<h:outputText value="Join Date:" />
						<h:outputText value="#{mStaff.staff.join_date}" />
						
						<h:outputText value="Email:" />
						<h:outputText value="#{mStaff.staff.email}" />
								
						<h:outputText value="Name:" />
						<h:outputText value="#{mStaff.staff.fullname}" />
						
						<h:outputText value="New Password:" />
						<h:inputSecret value="#{mStaff.staff.password}" id="acc_pwd"
							validator="#{mValidatorLib.PasswordValidate}" />
							
						<h:panelGroup />
						<rich:message for="acc_pwd" />
						
					</h:panelGrid>
					
					<a4j:commandButton value="Save" action="#{mStaff.update}"
							render="staff_table, messages" execute="pwdDialog"
							oncomplete="if (#{facesContext.maximumSeverity==null}) {#{p:component('pwdDialog')}.hide();}" />
					<a4j:commandButton value="Cancel" onclick="pwdDialog.hide(); return false;" />
			</p:dialog>
			
		</h:form>
	
	</article>
</ui:composition>
</html>